Skip to content

Conversation

@dgruano
Copy link

@dgruano dgruano commented Jan 27, 2025

Hi there!

This PR should address the feature request in #53.

image

I added a new field in the Notero preferences page that allows the user to choose whether to use https or notion url schema. Whenever an item is created, this preference is checked and the url is build accordingly. Interestingly, if the user changes the option, all URLs will be updated to match the desired schema.

I would really appreciate your opinion on two things @dvanoni :

  • I set the current default to the notion schema. Is that good?
  • We may want to improve the explanation in the preference section. Any suggestion?

Happy to hear your thoughts!

Summary by CodeRabbit

  • New Features

    • Added URL schema preference for link handling
    • Users can now choose between Notion app links (notion://) and web links (https://)
  • Documentation

    • Added localization strings explaining URL schema preferences
    • Provided clear user guidance about link saving options
  • User Interface

    • Introduced new preference section for link configuration
    • Added menu for selecting preferred URL schema

@coderabbitai
Copy link

coderabbitai bot commented Jan 27, 2025

Walkthrough

This pull request introduces a new URL schema preference for Notero, allowing users to choose between notion:// and https:// link formats when saving Notion attachments. The changes span multiple files, adding a new enumeration UrlSchema, updating preference handling logic, modifying the preferences interface, and introducing localization support for the new feature. The implementation provides users with more flexibility in how Notion links are saved and accessed.

Changes

File Change Summary
src/content/prefs/notero-pref.ts - Added UrlSchema enum with notion and https options
- Added urlSchema to NoteroPref enum
- Created getUrlSchemaPref function for preference validation
src/content/prefs/preferences.tsx - Added urlSchemaMenu property to Preferences class
- Implemented initUrlSchemaMenu method to set up URL schema selection
src/content/prefs/preferences.xhtml - Added new groupbox for URL schema preferences
- Included menulist for URL schema selection
src/content/sync/sync-regular-item.ts - Updated URL conversion logic to respect user's URL schema preference
src/locale/en-US/notero.ftl - Added localization entries for URL schema preferences

Sequence Diagram

sequenceDiagram
    participant User
    participant Preferences
    participant SyncItem
    participant NoteroPref

    User->>Preferences: Select URL Schema
    Preferences->>NoteroPref: Save urlSchema Preference
    SyncItem->>NoteroPref: Get urlSchema Preference
    alt Preference is notion://
        SyncItem->>SyncItem: Convert to notion:// URL
    else Preference is https://
        SyncItem->>SyncItem: Use original URL
    end
Loading

Possibly related PRs

Poem

🐰 A rabbit's tale of links so bright,
Notion or HTTPS, now set just right!
With schemas dancing, preferences clear,
Our coding magic brings users cheer!
Hop, hop, hurray for flexible might! 🌟

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (8)
src/content/prefs/preferences.xhtml (1)

87-91: Consider adding disabled state handling.

Other menulists in the file (e.g., notero-notionDatabase) have a disabled state. For consistency, consider adding the same behavior here if the URL schema should be disabled under certain conditions (e.g., when not connected to Notion).

    <menulist
      id="notero-urlSchema"
+     disabled="true"
      native="true"
      preference="extensions.notero.urlSchema"
    >
src/content/sync/sync-regular-item.ts (1)

32-37: Simplify the URL schema selection logic.

The current implementation is correct but can be made more concise:

-    // Decide link schema based on user preference
-    const notionURL =
-      getNoteroPref(NoteroPref.urlSchema) === UrlSchema.notion
-        ? convertWebURLToAppURL(response.url)
-        : response.url;
+    const notionURL = getNoteroPref(NoteroPref.urlSchema) === UrlSchema.notion
+      ? convertWebURLToAppURL(response.url)
+      : response.url;
src/locale/en-US/notero.ftl (1)

31-31: Enhance the description to better guide users.

The current description could be more helpful by explicitly stating the benefits and tradeoffs of each choice:

-notero-preferences-links-groupbox-description = Define if links are saved as notion:// or https:// links. Note that notion:// links are only accessible if the desktop app is installed.
+notero-preferences-links-groupbox-description = Choose between notion:// or https:// links. notion:// links open directly in the desktop app for a seamless experience but require the app to be installed. https:// links work universally but always open in the browser first.
src/content/prefs/notero-pref.ts (3)

23-26: Add JSDoc comments to document URL schema options.

Consider adding documentation to explain each schema option and its implications:

+/** URL schema options for Notion links */
 export enum UrlSchema {
+  /** Opens links directly in Notion desktop app but requires app installation */
   notion = 'notion',
+  /** Opens links in browser first, works universally */
   https = 'https',
 }

66-70: Strengthen type checking in getUrlSchemaPref.

The current implementation could be more strict in its type validation:

 function getUrlSchemaPref(value: Zotero.Prefs.Value): UrlSchema | undefined {
-  return Object.values(UrlSchema).includes(value as UrlSchema)
-    ? (value as UrlSchema)
-    : undefined;
+  return typeof value === 'string' && Object.values(UrlSchema).includes(value as UrlSchema)
+    ? (value as UrlSchema)
+    : undefined;
 }

23-26: Reconsider the default URL schema choice.

Currently, the default schema is set to notion://. While this provides a seamless experience for desktop app users, it might cause confusion for users who don't have the desktop app installed. Consider:

  1. Making https:// the default for universal compatibility
  2. Detecting desktop app presence to auto-select the appropriate schema
  3. Adding a first-run wizard to help users make an informed choice
src/content/prefs/preferences.tsx (2)

87-87: Consider async initialization consistency.

While the initialization follows the existing pattern, consider making initUrlSchemaMenu async for consistency with initPageTitleFormatMenu. This would allow for potential future async operations like loading saved preferences or validating schema options.

Also applies to: 96-96


116-126: Consider enhancing user guidance for URL schema selection.

Regarding the specific feedback points from the PR:

  1. The default choice of notion:// is reasonable as it provides native app integration, but consider:

    • Adding a comment in the code explaining this default choice
    • Documenting the implications of each choice in the UI
    • Potentially making this choice during first-time setup
  2. To improve explanations in preferences:

    • Add help text explaining when to use each schema
    • Include examples of how links will appear
    • Consider adding a link to documentation

Example help text structure:

  • notion://: Opens links in the Notion desktop app (recommended for desktop users)
  • https://: Opens links in web browser (recommended for users without the desktop app)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d7fea4f and bc0c2a2.

📒 Files selected for processing (5)
  • src/content/prefs/notero-pref.ts (5 hunks)
  • src/content/prefs/preferences.tsx (5 hunks)
  • src/content/prefs/preferences.xhtml (1 hunks)
  • src/content/sync/sync-regular-item.ts (2 hunks)
  • src/locale/en-US/notero.ftl (1 hunks)
🔇 Additional comments (3)
src/content/prefs/preferences.tsx (3)

21-25: LGTM! Clean import organization.

The import statement is well-organized and properly grouped with related preference imports.


64-64: LGTM! Property declaration follows established patterns.

The urlSchemaMenu property is properly typed and follows the existing pattern of other menu element declarations in the class.


116-126: 🛠️ Refactor suggestion

Several improvements needed for URL schema initialization.

The implementation could be enhanced in the following areas:

  1. Load the default value from saved preferences instead of hardcoding
  2. Add localization for schema labels
  3. Add JSDoc documentation explaining the purpose and behavior
  4. Add tooltips or help text explaining the implications of each schema choice

Here's a suggested implementation:

+ /**
+  * Initializes the URL schema selection menu.
+  * This allows users to choose between notion:// and https:// URL formats
+  * for Notion links.
+  */
 private initUrlSchemaMenu(): void {
   const menuItems = Object.values(UrlSchema).map<MenuItem>((schema) => ({
     disabled: false,
-    label: `${schema}://`,
+    l10nId: `notero-preferences-url-schema-${schema}`,
     value: schema,
   }));

   setMenuItems(this.urlSchemaMenu, menuItems);
   this.urlSchemaMenu.disabled = false;
-  this.urlSchemaMenu.value = UrlSchema.notion; // Set default value to Notion schema
+  // Load saved preference or fall back to default
+  this.urlSchemaMenu.value = Zotero.Prefs.get('extensions.notero.urlSchema') || UrlSchema.notion;
+
+  // Add tooltip explaining the implications
+  document.l10n.setAttributes(
+    this.urlSchemaMenu,
+    'notero-preferences-url-schema-tooltip'
+  );
 }

This implementation addresses the PR objectives by:

  • Maintaining the default of "notion:" schema while making it configurable
  • Improving explanations through localized labels and tooltips

Let's verify if the necessary L10N strings are defined:

Copy link
Owner

@dvanoni dvanoni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dgruano, thanks for opening this PR! I appreciate your patience as it took me a while to get around to looking at it.

Some thoughts regarding your questions:

I set the current default to the notion schema. Is that good?

I wonder if it makes more sense to default to https since that should work for everyone regardless of whether they have the Notion desktop app installed. It seems like a "safer" option to me.

We may want to improve the explanation in the preference section. Any suggestion?

I imagine most users won't know what a "URL scheme" is. What if we update the explanation to something like this:

Select the format for Notion links saved on each item. The Notion desktop app must be installed to open desktop links.

And change the label to Notion Link Format:

And change the options to:

  • Web
  • Desktop

pageTitleFormat = 'pageTitleFormat',
syncNotes = 'syncNotes',
syncOnModifyItems = 'syncOnModifyItems',
urlSchema = 'urlSchema',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to prefix the pref name with notion so that we know which URLs we're talking about.

Also, the correct term is scheme rather than schema, so we'll want to update that everywhere.

Suggested change
urlSchema = 'urlSchema',
notionUrlScheme = 'notionUrlScheme',


setMenuItems(this.urlSchemaMenu, menuItems);
this.urlSchemaMenu.disabled = false;
this.urlSchemaMenu.value = UrlSchema.notion; // Set default value to Notion schema
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line doesn't appear to be working for me.

CleanShot 2025-04-27 at 16 04 56@2x

I think we'll instead want to set the default in src/prefs.js.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants